package com.lyf.core.common;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

import java.util.List;

public class BaseAppliction extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        startInit();
    }

    public void startInit(){
        String processName = getProcessName(this,
                android.os.Process.myPid());
        if (processName != null) {
            boolean defaultProcess = processName.equals(getPackageName());
            if (defaultProcess) {
                //必要的初始化资源操作
                init();
            }
        }
    }

    public static String getProcessName(Context cxt, int pid) {
        ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningApps = am.getRunningAppProcesses();
        if (runningApps == null) {
            return null;
        }
        for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
            if (procInfo.pid == pid) {
                return procInfo.processName;
            }
        }
        return null;
    }

    public void init(){
    }
}
